import { apiClient } from '../config'
import type {
  Response,
  GetRolePagedListAsyncParams,
  GetRolePagedListAsyncResponse,
  AddRoleAsyncParams,
  UpdateRoleAsyncParams,
  IsBandUserAsyncParams,
  GetUserRoleInfoAsyncParams,
  IsBindMenuAsyncParams,
} from '../../types/Role'

/**
 * 分页查询用户列表
 * @param params 查询参数
 * @returns 用户列表响应
 */
export const getRolePagedListAsync = async (
  params: GetRolePagedListAsyncParams,
): Promise<GetRolePagedListAsyncResponse> => {
  return await apiClient.get('/Role/GetRolePagedListAsync', { params })
}

/**
 * 添加用户
 * @param params 添加用户参数
 * @returns 操作结果
 */
export const addRoleAsync = async (params: AddRoleAsyncParams): Promise<Response> => {
  return await apiClient.post('/Role/AddRoleAsync', params, {
    headers: {
      'Content-Type': 'application/json',
    },
  })
}

/**
 * 修改用户信息
 * @param params 修改用户参数
 * @returns 操作结果
 */
export const updateRoleAsync = async (params: UpdateRoleAsyncParams): Promise<Response> => {
  return await apiClient.post('/Role/UpdateRoleAsync', params, {
    headers: {
      'Content-Type': 'application/json',
    },
  })
}

/**
 * 启用/停用用户
 * @param params 启用停用参数
 * @returns 操作结果
 */
export const updateRoleStatusAsync = async (id: number): Promise<Response> => {
  return await apiClient.post('/Role/UpdateRoleStatusAsync', id, {
    headers: {
      'Content-Type': 'application/json',
    },
  })
}

/**
 * 批量启用/停用用户
 * @param ids 用户ID数组
 * @returns 操作结果
 */
export const updateRolesStatusAsync = async (ids: number[]): Promise<Response> => {
  return await apiClient.post('/Role/UpdateRolesStatusAsync', ids, {
    headers: {
      'Content-Type': 'application/json',
    },
  })
}

/**
 * 获取穿梭数据
 * @param params 获取数据参数
 * @returns 操作结果
 */
export const getUserRoleInfoAsync = async (id: number): Promise<Response> => {
  return await apiClient.post('/Role/GetUserRoleInfoAsync', id, {
    headers: {
      'Content-Type': 'application/json',
    },
  })
}

/**
 * 获取角色绑定菜单树数据
 * @returns 操作结果
 */
export const getMenuTreeWithRoleStatusAsync = async (
  params: GetUserRoleInfoAsyncParams,
): Promise<Response> => {
  return await apiClient.get('/Role/GetMenuTreeWithRoleStatusAsync', { params })
}

/**
 * 绑定/解绑
 * @param params 绑定/解绑用户参数
 * @returns 操作结果
 */
export const isBandUserAsync = async (params: IsBandUserAsyncParams): Promise<Response> => {
  return await apiClient.post('/Role/IsBandUserAsync', params, {
    headers: {
      'Content-Type': 'application/json',
    },
  })
}

/**
 * 绑定/解绑
 * @param params 绑定/解绑用户参数
 * @returns 操作结果
 */
export const isBindMenuAsync = async (params: IsBindMenuAsyncParams): Promise<Response> => {
  return await apiClient.post('/Role/IsBindMenuAsync', params, {
    headers: {
      'Content-Type': 'application/json',
    },
  })
}

export default {
  getRolePagedListAsync,
  addRoleAsync,
  updateRoleAsync,
  updateRoleStatusAsync,
  updateRolesStatusAsync,
  getUserRoleInfoAsync,
  isBandUserAsync,
  getMenuTreeWithRoleStatusAsync,
  isBindMenuAsync,
}
